#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2020-08-26 15:47:26
# @Author  : Zuo Zhongfei (zuozhongfei@126.com)
# @Link    : www
# @Version : $Id$

import os


class Car():
    """docstring for Car"""

    def __init__(self, name, price):
        super(Car, self).__init__()
        self.name = name
        self.price = price
        self.mileage = 0

    def describe_car(self):
        print('This car is called ' + self.name + " and it's worth " + str(self.price))

    def run_car(self):
        print("The " + self.name + " is running")

    def horns_car(self):
        print("di di di ~~~ 都给我让开")

    def read_mileage(self):
        print("This car has " + str(self.mileage) + " miles on it")

    def update_mileage(self, mileage):
        # 设置里程数
        # 禁止将里程表读书往回调
        if mileage >= self.mileage:
            self.mileage = mileage
        else:
            print("You can't roll back an mileage")


# bmw = Car("bmw", 10000000)
# print(bmw.name)
# bmw.describe_car()
# bmw.run_car()
# bmw.horns_car()
# bmw.read_mileage()

# # 修改属性值
# # 1：直接修改实例的属性值
# bmw.mileage = 23
# bmw.read_mileage()

# # 2：通过方法进行修改
# bmw.update_mileage(30)
# bmw.read_mileage()

# bmw.update_mileage(20)


# 电动汽车类，继承与Car类
class ElectricCar(Car):
    """电动汽车类"""

    def __init__(self, name, price):
        super().__init__(name, price)
        # 为子类扩展一个电瓶容量的属性
        self.battery_size = 70

    def describe_battery(self):
        print("This car has a " + str(self.battery_size) + "-KWh battery")

    # 重写父类的方法，子类实例调用这个方法时，就会调用子类中的实现，替换父类中的实现
    def horns_car(self):
        print("电动车的 di di di ~~~ 都给我让开")


# my_tesla = ElectricCar("tesla", 800000)
# print(my_tesla.describe_car())
# my_tesla.run_car()
# my_tesla.describe_battery()
# my_tesla.horns_car()
